# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Kaiting Chen <kaitocracy@gmail.com>
# Contributor: Daniel J Griffiths <ghost1227@archlinux.us>
# Contributor: Kevin Piche <kevin@archlinux.org>

pkgname=stunnel
pkgver=5.71
pkgrel=1
pkgdesc="A program that allows you to encrypt arbitrary TCP connections inside SSL"
arch=('loong64' 'x86_64')
url="https://www.stunnel.org/"
license=('GPL')
depends=('openssl' 'perl' 'libnsl' 'systemd-libs')
makedepends=('systemd')
source=(
  "https://www.stunnel.org/downloads/archive/5.x/$pkgname-$pkgver.tar.gz"{,.asc}
  'Makefile.patch'
  'sysusers.conf'
  'tmpfiles.conf'
)
sha512sums=('c7004f48b93b3415305eec1193d51b7bf51a3bdd2cdc9f6ae588f563b32408b1ecde83b9f3f5b658f945ab5bcc5124390c38235394aad4471bf5b666081af2a2'
            'SKIP'
            '9c669b6a8ebfb2ed26ba90578a12a5de4c4667100ffaa02725650f451ed02b2eab4a77f00f20cc3c7cab761312b658059fcf259ef58e273541ca202c36a18095'
            '8a7199b94cda5da8c0b99b25daf4bead1398a28975eb6813139744a8a962db3aa058bc4c9e7ee4121a52c62c2e2c2ed46d1739414927b210e0ac68da48a7ef5e'
            '8e06ec39547ce5991217e551e563f5d212742afda94da801ec266c632375aae489594d14815fe596319d9881eb5a58e32bf05baa69f3a9d1bae554419f5ac1bb')
b2sums=('d323363c7bfdd6c0b7931b84a6069cf9a8337e967c31e14d15976d7932f0c0d6f40f7a1cbf5abbdff0e9edc52176cdcead4f848653088193b2debf4e77443b42'
        'SKIP'
        'a1eacbfc7815a0e2eb6cda434639e315a94c27bdc59ad93090a00c8fbcdd760f9db1f22dbeaacc99615a44001444c295136c2ed92e57901d141478b661078ee3'
        '0022d76a55d540f5d9d7b3bd3709665f80e5aa3293479245ea70845a7ceadf52f9b259f38d8b1b312fea29950c9fa4799282156c9e78d00d0fcda77f1c526029'
        'cedd3eccd1964dcc86255fca0e47fe692a2619fbcbc576480adf193192a2218972d07961a3ab4d30f095c308844f25fe71cdf285bde201050be24d4ce0ca80d3')
validpgpkeys=('AC915EA30645D9D3D4DAE4FEB1048932DD3AAAA3') # Michał Trojnara <Michal.Trojnara@stunnel.org>

prepare() {
  cd "$pkgname-$pkgver"

  # skip generation of $pkgdir/var
  patch -p0 <"$srcdir/Makefile.patch"

  # ensure user/group is set to stunnel
  sed \
    -e "s:\(nobody\|@DEFAULT_GROUP@\):stunnel:g" \
    -i tools/stunnel.conf-sample.in
}

build() {
  cd "$pkgname-$pkgver"

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --enable-ipv6 \
    --disable-libwrap

  make
}

package() {
  cd "$pkgname-$pkgver"

  make DESTDIR="$pkgdir" install

  # systemd integration
  install -vDm644 tools/stunnel.service "$pkgdir/usr/lib/systemd/system/stunnel.service"
  install -vDm644 "$srcdir/sysusers.conf" "$pkgdir/usr/lib/sysusers.d/stunnel.conf"
  install -vDm644 "$srcdir/tmpfiles.conf" "$pkgdir/usr/lib/tmpfiles.d/stunnel.conf"

  # bash completion missing from 5.65 onwards
  install -vDm644 tools/stunnel.bash -t "$pkgdir/usr/share/bash-completion/completions"
}
